package gameobject;

import java.awt.event.KeyEvent;
import simulation.Game;


/**
 * Creates a second type of player
 * can only move left and right
 * 
 * @author michele
 * 
 */
public class Spacecraft extends Player {

    public Spacecraft () {
        super();
    }

    public Spacecraft (Game game, Number dx, Number dy, Number speed, Number HP, Number damage) {
        super(game, dx, dy, speed, HP, damage);
    }

    @Override
    public void handleKeyPressed (KeyEvent e) {
        int lastKeyPressed = e.getKeyCode();
        // int speedIncrement =
        // Integer.parseInt(getResource("SpeedIncrementOnKeyPress"));
        if (lastKeyPressed == KeyEvent.VK_LEFT) {
            // setDx(getDx() - speedIncrement);
            setDx(-1);
        }
        if (lastKeyPressed == KeyEvent.VK_RIGHT) {
            // setDx(getDx() + speedIncrement);
            setDx(1);
        }
    }

    @Override
    public void handleKeyReleased (KeyEvent e) {
        int lastKeyReleased = e.getKeyCode();
        if ((lastKeyReleased == KeyEvent.VK_LEFT) || (lastKeyReleased == KeyEvent.VK_RIGHT)) {
            setDx(0);
        }
        if (lastKeyReleased == KeyEvent.VK_SPACE) {
            Missile missile =
                    new Missile(getGame(), this, getX(), getY(), 0, -1,
                                Integer.parseInt(getResource("MissileSpeed")), 1, 1);
            addOwnSprite(missile);
        }
    }
}
